package cn.com.utt.unms.mapper;

import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import cn.com.utt.unms.pojo.Rf;

@Mapper
public interface RfMapper {
	
	@Delete({"<script>",
	    "delete ", 
	    "FROM rf",
	    "WHERE ", 
	    "id IN", 
	      "<foreach item='item' index='index' collection='rfIds'",
	        "open='(' separator=',' close=')'>",
	        "#{item}",
	      "</foreach>",
	"</script>"})
	void delete(@Param("rfIds")long[] rfIds);
	
	@Select("SELECT * FROM rf  WHERE user_id=#{userId}") 
	List<Rf> queryRfsByUserID(@Param("userId")long userId);
	
	@Insert("insert into rf(user_id,`name`,g24_en,g24_standard,g24_channel,g24_bandwidth,g24_bitrate,g24_power_mode,g24_power_level,g24_beacon_interval,g24_wmm_en,g24_romaing_en,g24_wmm_relate,g24_roaming_threshold,g24_short_interval,g24_short_preamble,g5_en,g5_standard,g5_channel,g5_bandwidth,g5_vht_bandwidth,g5_power_mode,g5_power_level,g5_beacon_interval,g5_wmm_en,g5_romaing_en,g5_wmm_relate,g5_roaming_threshold,g5_short_interval,g5_short_preamble,g24_clients,g5_clients) "
			+ "values(#{userId},#{name},#{g24En},#{g24Standard},#{g24Channel},#{g24Bandwidth},"
			+ "#{g24Bitrate},#{g24PowerMode},#{g24PowerLevel},#{g24BeaconInterval},#{g24WmmEn},#{g24RomaingEn},#{g24WmmRelate},#{g24Roamingthreshold},#{g24ShortInterval},#{g24ShortPreamble},"
			+ "#{g5En},#{g5Standard},#{g5Channel},#{g5Bandwidth},#{g5VhtBandwidth},#{g5PowerMode},#{g5PowerLevel},#{g5BeaconInterval},#{g5WmmEn},#{g5RomaingEn},#{g5WmmRelate},#{g5Roamingthreshold},#{g5ShortInterval},#{g5ShortPreamble},"
			+ "#{g24Clients},#{g5Clients})")
	void save(Rf rf);
	
	@Select("select id,user_id as userId,`name`,g24_en as g24En,g24_standard as g24Standard,g24_channel as g24Channel,g24_bandwidth as g24Bandwidth,g24_bitrate as g24Bitrate,g24_power_mode as g24PowerMode,g24_power_level as g24PowerLevel,g24_beacon_interval as g5BeaconInterval,g24_wmm_en as g24WmmEn,g24_romaing_en as g24RomaingEn,g24_wmm_relate as g24WmmRelate,g24_roaming_threshold as g24Roamingthreshold,g24_short_interval as g24ShortInterval,g24_short_preamble as g24ShortPreamble,"
			+ "g5_en as g5En,g5_standard as g5Standard,g5_channel as g5Channel,g5_bandwidth as g5Bandwidth,g5_vht_bandwidth as g5VhtBandwidth,g5_power_mode as g5PowerMode,g5_power_level as g5PowerLevel,g5_beacon_interval as g5BeaconInterval,g5_wmm_en as g5WmmEn,g5_romaing_en as g5RomaingEn,g5_wmm_relate as g5WmmRelate,g5_roaming_threshold as g5Roamingthreshold,g5_short_interval as g5ShortInterval,g5_short_preamble as g5ShortPreamble,"
			+ "g24_clients as g24Clients,g5_clients as g5Clients from rf where id=#{id}")
	Rf findById(@Param("id")long id);
	
	@Select({"<script>",
	    "SELECT user_id as userId ", 
	    "FROM rf",
	    "WHERE ", 
	    "id IN", 
	      "<foreach item='item' index='index' collection='rfIds'",
	        "open='(' separator=',' close=')'>",
	        "#{item}",
	      "</foreach>",
	"</script>"})
	List<Rf> findByIds(@Param("rfIds")long[] rfIds);
	
	@Update("update rf set name=#{name},g24_en=#{g24En},g24_standard=#{g24Standard},g24_channel=#{g24Channel},g24_bandwidth=#{g24Bandwidth},g24_bitrate=#{g24Bitrate},g24_power_mode=#{g24PowerMode},g24_power_level=#{g24PowerLevel},g24_beacon_interval=#{g24BeaconInterval},g24_wmm_en=#{g24WmmEn},g24_romaing_en=#{g24RomaingEn},g24_wmm_relate=#{g24WmmRelate},g24_roaming_threshold=#{g24Roamingthreshold},g24_short_interval=#{g24ShortInterval},g24_short_preamble=#{g24ShortPreamble},"
			+ "g5_en=#{g5En},g5_standard=#{g5Standard},g5_channel=#{g5Channel},g5_bandwidth=#{g5Bandwidth},g5_vht_bandwidth=#{g5VhtBandwidth},g5_power_mode=#{g5PowerMode},g5_power_level=#{g5PowerLevel},g5_beacon_interval=#{g5BeaconInterval},g5_wmm_en=#{g5WmmEn},g5_romaing_en=#{g5RomaingEn},g5_wmm_relate=#{g5WmmRelate},g5_roaming_threshold=#{g5Roamingthreshold},g5_short_interval=#{g5ShortInterval},g5_short_preamble=#{g5ShortPreamble},"
			+ "g24_clients=#{g24Clients},g5_clients=#{g5Clients} where id=#{id}")
	void update(Rf rf);
	
	@Select({"<script>",
	    "SELECT *", 
	    "FROM rf",
	    "WHERE 1=1 and "
	    + "user_id=#{userId} ",
	      "<if test='searchs != null'>",
	      "<foreach item='item' index='index' collection='searchs'",
	        "open='and' separator='and' close=''>",
	        "<choose>",
	        "<when test='item.op != \"like\"'>",
	        "${item.column}",
	        " = ",
	        "#{item.value}",
	        "</when>",
	        "<otherwise>",
	        "${item.column}",
	        " like ",
	        "'%${item.value}%'",
	        "</otherwise>",
	        "</choose>",
	      "</foreach>",
	      "</if>",
	      "<if test='orderColumn != null'>",
	      "order by ${orderColumn} ${orderDirection}",
	      "</if>",
	      "limit #{start},#{rows}",
	    "</script>"})
	List<Rf> queryConditions(Map<String, Object> conditions);
	
	@Select({"<script>",
	    "SELECT count(*) as total", 
	    "FROM rf",
	    "WHERE 1=1 and "
	    + "user_id=#{userId} ",
	      "<if test='searchs != null'>",
	      "<foreach item='item' index='index' collection='searchs'",
	        "open='and' separator='and' close=''>",
	        "<choose>",
	        "<when test='item.op != \"like\"'>",
	        "${item.column}",
	        " = ",
	        "#{item.value}",
	        "</when>",
	        "<otherwise>",
	        "${item.column}",
	        " like ",
	        "'%${item.value}%'",
	        "</otherwise>",
	        "</choose>",
	      "</foreach>",
	      "</if>",
	    "</script>"})
	int queryConditionsCount(Map<String, Object> conditions);
	
}
